<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  <title>大括号换行即编译错误 | Chenye!</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="##大括号的圣战 你们写C/C++代码时是否换行呢？ 就像下面这样: 不换行+无空格党 123int main()&amp;#123;    return 0;&amp;#125; 不换行+空格党 123int main() &amp;#123;    return 0;&amp;#125; 换行党 1234int main()&amp;#123;    return 0;&amp;#125; 反正对于我来说，坚决支持不换行+无空格的。 今天有">
<meta name="keywords" content="大括号圣战">
<meta property="og:type" content="article">
<meta property="og:title" content="大括号换行即编译错误">
<meta property="og:url" content="http://chenyejin.github.io/2017/08/20/No换行/index.html">
<meta property="og:site_name" content="Chenye!">
<meta property="og:description" content="##大括号的圣战 你们写C/C++代码时是否换行呢？ 就像下面这样: 不换行+无空格党 123int main()&amp;#123;    return 0;&amp;#125; 不换行+空格党 123int main() &amp;#123;    return 0;&amp;#125; 换行党 1234int main()&amp;#123;    return 0;&amp;#125; 反正对于我来说，坚决支持不换行+无空格的。 今天有">
<meta property="og:locale" content="zh-CN">
<meta property="og:updated_time" content="2017-09-09T12:16:40.130Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="大括号换行即编译错误">
<meta name="twitter:description" content="##大括号的圣战 你们写C/C++代码时是否换行呢？ 就像下面这样: 不换行+无空格党 123int main()&amp;#123;    return 0;&amp;#125; 不换行+空格党 123int main() &amp;#123;    return 0;&amp;#125; 换行党 1234int main()&amp;#123;    return 0;&amp;#125; 反正对于我来说，坚决支持不换行+无空格的。 今天有">
  
    <link rel="alternate" href="/atom.xml" title="Chenye!" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png">
  
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  <link rel="stylesheet" href="/css/style.css">
  

</head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/" id="logo">Chenye!</a>
      </h1>
      
        <h2 id="subtitle-wrap">
          <a href="/" id="subtitle">2444&#39;s Home</a>
        </h2>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/">Home</a>
        
          <a class="main-nav-link" href="/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="搜索"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="http://chenyejin.github.io"></form>
      </div>
    </div>
  </div>
</header>
      <div class="outer">
        <section id="main"><article id="post-No换行" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2017/08/20/No换行/" class="article-date">
  <time datetime="2017-08-20T14:04:30.000Z" itemprop="datePublished">2017-08-20</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      大括号换行即编译错误
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <p>##大括号的圣战</p>
<p>你们写C/C++代码时是否换行呢？</p>
<p>就像下面这样:</p>
<p>不换行+无空格党</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>&#123;</div><div class="line">    <span class="keyword">return</span> <span class="number">0</span>;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>不换行+空格党</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span> </span>&#123;</div><div class="line">    <span class="keyword">return</span> <span class="number">0</span>;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>换行党</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span></div><div class="line">&#123;</div><div class="line">    <span class="keyword">return</span> <span class="number">0</span>;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>反正对于我来说，坚决支持不换行+无空格的。</p>
<p>今天有一款“编译器”h++“发布”</p>
<p>这款“编译器”的主体功能甚至是调用g++的，</p>
<p>唯一不同的就是会审查代码中是否有奇怪的换行大括号存在。</p>
<p>是一个单文件的cpp，因此你们可以直接g++ -o h++.exe h++.cpp把它编译出来。</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div></pre></td><td class="code"><pre><div class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;cstdio&gt;</span></span></div><div class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;cstdlib&gt;</span></span></div><div class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;string&gt;</span></span></div><div class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</div><div class="line"><span class="built_in">string</span> cmd=<span class="string">"g++ "</span>;</div><div class="line"><span class="function"><span class="keyword">void</span> <span class="title">check</span><span class="params">(FILE*in)</span></span>&#123;</div><div class="line">	<span class="keyword">if</span>(in==<span class="literal">NULL</span>)&#123;</div><div class="line">		<span class="built_in">printf</span>(<span class="string">"File not found!\n"</span>);<span class="built_in">exit</span>(<span class="number">1</span>);</div><div class="line">	&#125;</div><div class="line">	<span class="keyword">char</span> ch=fgetc(in);</div><div class="line">	<span class="keyword">int</span> line=<span class="number">1</span>,col=<span class="number">0</span>;</div><div class="line">	<span class="keyword">while</span>(ch!=EOF)&#123;</div><div class="line">		<span class="keyword">if</span>(ch==<span class="string">'\n'</span>) line++,col=<span class="number">0</span>;</div><div class="line">		<span class="keyword">if</span>(ch==<span class="string">')'</span>)&#123;</div><div class="line">			ch=fgetc(in);col++;</div><div class="line"><span class="comment">//			printf("%d %d %d\n",line,col,ch);</span></div><div class="line"><span class="comment">//			if(ch!=';'&amp;&amp;ch!='&#123;'&amp;&amp;ch!=' '&amp;&amp;ch!='-'&amp;&amp;ch!='+'&amp;&amp;ch!='*'&amp;&amp;ch!='/'&amp;&amp;ch!='\''&amp;&amp;ch!='.'&amp;&amp;ch!='('&amp;&amp;ch!=')'&amp;&amp;ch!='='&amp;&amp;ch!=','&amp;&amp;ch!='%'&amp;&amp;ch&lt;'A'&amp;&amp;ch&gt;'Z'&amp;&amp;ch&lt;'a'&amp;&amp;ch&gt;'z')&#123;</span></div><div class="line">			<span class="keyword">if</span>(ch==<span class="string">'\n'</span>||ch==<span class="string">'\r'</span>)&#123;</div><div class="line">				<span class="built_in">fprintf</span>(<span class="built_in">stderr</span>,<span class="string">"Z:\\The file that you opened.:%d:%d error :!WRONG Code style!In line %d,the cols of %d\n"</span>,line,col,line,col);</div><div class="line">				<span class="built_in">exit</span>(<span class="number">0</span>);</div><div class="line">			&#125;</div><div class="line">		&#125;</div><div class="line">		ch=fgetc(in);col++;</div><div class="line">	&#125;</div><div class="line">&#125;</div><div class="line">FILE *fp;</div><div class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">(<span class="keyword">int</span> argc,<span class="keyword">char</span> **argv)</span></span>&#123;</div><div class="line">	<span class="built_in">string</span> s[argc+<span class="number">1</span>];</div><div class="line">	<span class="keyword">if</span>(argc&lt;<span class="number">2</span>)&#123;</div><div class="line">		<span class="built_in">printf</span>(<span class="string">"Where is the input?FUCK!\n"</span>);</div><div class="line">		<span class="keyword">return</span> <span class="number">0</span>;</div><div class="line">	&#125;</div><div class="line">	<span class="keyword">int</span> pos;</div><div class="line">	<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i&lt;argc;i++) </div><div class="line">		s[i]=argv[i];</div><div class="line">	<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i&lt;argc;i++)&#123;</div><div class="line">		<span class="keyword">int</span> p=s[i].size()<span class="number">-1</span>;</div><div class="line">		<span class="keyword">if</span>(p&lt;<span class="number">4</span>) <span class="keyword">continue</span>;</div><div class="line"><span class="comment">//		printf("%s\n",s[i].substr(p,p-3-1).c_str());</span></div><div class="line">		<span class="keyword">if</span>(s[i].substr(p<span class="number">-3</span>,p)==<span class="string">".cpp"</span>)&#123;</div><div class="line">			pos=i;<span class="keyword">break</span>;</div><div class="line">		&#125;</div><div class="line">	&#125;</div><div class="line">	<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i&lt;argc;i++)&#123;</div><div class="line">		<span class="keyword">if</span>(s[i][<span class="number">0</span>]==<span class="string">'-'</span>&amp;&amp;s[i][<span class="number">1</span>]==<span class="string">'I'</span>)&#123;</div><div class="line">			cmd+=<span class="string">"-I\""</span>+s[i].substr(<span class="number">2</span>,s[i].size()<span class="number">-1</span>)+<span class="string">"\""</span>;cmd+=<span class="string">" "</span>;<span class="keyword">continue</span>;</div><div class="line">		&#125;</div><div class="line">		<span class="keyword">if</span>(s[i][<span class="number">0</span>]==<span class="string">'-'</span>&amp;&amp;s[i][<span class="number">1</span>]==<span class="string">'L'</span>)&#123;</div><div class="line">			cmd+=<span class="string">"-L\""</span>+s[i].substr(<span class="number">2</span>,s[i].size()<span class="number">-1</span>)+<span class="string">"\""</span>;cmd+=<span class="string">" "</span>;<span class="keyword">continue</span>;</div><div class="line">		&#125;</div><div class="line">		<span class="keyword">if</span>(s[i][<span class="number">0</span>]!=<span class="string">'-'</span>) cmd+=<span class="string">"\""</span>;</div><div class="line">		cmd+=argv[i];</div><div class="line">		<span class="keyword">if</span>(s[i][<span class="number">0</span>]!=<span class="string">'-'</span>) cmd+=<span class="string">"\""</span>;</div><div class="line">		cmd+=<span class="string">" "</span>;</div><div class="line">	&#125;</div><div class="line">	fp=fopen(s[pos].c_str(),<span class="string">"r"</span>);</div><div class="line"><span class="comment">//	printf("CPP文件路径:%s\n",s[pos].c_str());</span></div><div class="line"><span class="comment">//	printf("编译指令:%s\n",cmd.c_str());</span></div><div class="line"><span class="comment">////	fp=fopen("h++.cpp","r");</span></div><div class="line">	check(fp);</div><div class="line">	fclose(fp);</div><div class="line">	system(cmd.c_str());</div><div class="line">	<span class="keyword">return</span> <span class="number">0</span>;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>###最后:</p>
<p>###换行派都Go Die吧!!!不换行派万岁</p>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://chenyejin.github.io/2017/08/20/No换行/" data-id="cj7d9webv000058u1nksa6zgd" class="article-share-link">Share</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/大括号圣战/">大括号圣战</a></li></ul>

    </footer>
  </div>
  
    
<nav id="article-nav">
  
  
    <a href="/2017/07/30/7-29-总结/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">7-29-总结</div>
    </a>
  
</nav>

  
</article>

</section>
        
          <aside id="sidebar">
  
    

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">标签</h3>
    <div class="widget">
      <ul class="tag-list"><li class="tag-list-item"><a class="tag-list-link" href="/tags/大括号圣战/">大括号圣战</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/总结-NOIP-2017-RP/">总结,NOIP,2017,RP</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/提示-醒目-Hello-World-第二篇/">提示,醒目,Hello,World,第二篇</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">标签云</h3>
    <div class="widget tagcloud">
      <a href="/tags/大括号圣战/" style="font-size: 10px;">大括号圣战</a> <a href="/tags/总结-NOIP-2017-RP/" style="font-size: 10px;">总结,NOIP,2017,RP</a> <a href="/tags/提示-醒目-Hello-World-第二篇/" style="font-size: 10px;">提示,醒目,Hello,World,第二篇</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">归档</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/08/">八月 2017</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/07/">七月 2017</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">最新文章</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/2017/08/20/No换行/">大括号换行即编译错误</a>
          </li>
        
          <li>
            <a href="/2017/07/30/7-29-总结/">7-29-总结</a>
          </li>
        
          <li>
            <a href="/2017/07/23/post/">post</a>
          </li>
        
          <li>
            <a href="/2017/07/22/hello-world/">Hello World</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2017 Chenye Jin<br>
      Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>
    </div>
    <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>


  <link rel="stylesheet" href="/fancybox/jquery.fancybox.css">
  <script src="/fancybox/jquery.fancybox.pack.js"></script>


<script src="/js/script.js"></script>

  </div>
</body>
</html>